package acwing._2LanQiao._9DP;
/**
 * @Project : AlgorithmLearning
 * @Package : ACWing._2LanQiao._9DP
 * @File : Q1070.java
 * @Author : WangRuoyu
 * @Date : 2023/3/24 16:35
 */

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

public class Q1070 {

    static boolean check(char x, char y) {
        if (x == '(' && y == ')') return true;
        if (x == '[' && y == ']') return true;
        return false;
    }

    public static void main(String[] args) throws IOException {
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        String line = br.readLine();
        int n = line.length();

        int[][] f = new int[n][n];
        for (int i = 0; i < n; i ++ ) f[i][i] = 1;
        for (int len = 2; len <= n; ++len) {
            for (int i = 0; i < n - len + 1; ++i) {
                int j = i + len - 1;
                f[i][j] = Integer.MAX_VALUE;
                if (check(line.charAt(i), line.charAt(j))) {
                    f[i][j] = f[i + 1][j - 1];
                }
                f[i][j] = Math.min(f[i][j], Math.min(f[i + 1][j], f[i][j - 1]) + 1);
                for (int k = i; k < j; ++k) {
                    f[i][j] = Math.min(f[i][j], f[i][k] + f[k + 1][j]);
                }
            }
        }
        System.out.println(f[0][n - 1]);
    }
}